<?php
Yii::app()->clientScript->registerScriptFile($this->adminPath."/js/art-dialog/jquery.artDialog.js",CClientScript::POS_HEAD);
Yii::app()->clientScript->registerScriptFile($this->adminPath."/js/art-dialog/plugins/iframeTools.js",CClientScript::POS_HEAD);
Yii::app()->clientScript->registerScriptFile($this->adminPath."/js/post/uploadify/jquery.uploadify.min.js",CClientScript::POS_HEAD);
?>
<link rel="stylesheet" type="text/css" href="<?php echo $this->adminPath; ?>/css/jquery-ui.css" />
<link rel="stylesheet" type="text/css" href="<?php echo $this->adminPath; ?>/js/art-dialog/skins/blue.css" />
<link rel="stylesheet" type="text/css" href="<?php echo $this->adminPath; ?>/js/post/uploadify/uploadify.css">
<div class="st-form-line">
<form>
  <input id="uploadify" name="uploadify" type="file" multiple="false">
  <ul id="fileListWarp">
  </ul>
  <div id="fileQueue" style="clear:both"></div>
</form>
    </div>
<script type="text/javascript">
		
$(function() {
    var Warp = art.dialog.data('Warp');
    var Name = art.dialog.data('Name');
    $('#uploadify').uploadify({
        'buttonText': '选择文件..',
        'fileObjName': 'imgFile',
        'method': 'post',
        'multi': false,
		'queueID': 'fileQueue',
        'uploadLimit': 1,
        'fileTypeExts': '*.gif;*.png;*.jpg;*.bmp;',
        'buttonImage': '<?php echo $this->adminPath; ?>/js/post/uploadify/select.png',
        'formData': {
            'sessionId'   : '<?php echo session_id(); ?>',
			'timestamp'   : '<?php echo time();?>',
			'token'       : '<?php echo md5('unique_salt'.time()); ?>'
        },
        'swf': '<?php echo $this->adminPath; ?>/js/post/uploadify/uploadify.swf',
        'uploader': '<?php echo Yii::app()->createAbsoluteUrl('admin/uploadify/basicExecute')?>',
        'onUploadStart': function(file) {
            $('#uploadify').uploadify('settings', 'formData', {
                'iswatermark': $("#iswatermark").attr("checked")
            });
        },
        'onUploadSuccess': function(file, data, response) {
            var json = $.parseJSON(data);
            if (json.state == 'success') {
                $("#fileListWarp").html('<li id="image_' + json.fileId + '"><img src="<?php echo Yii::app()->homeUrl ?>'+json.file+'" width="40" height="40"  align="absmiddle"/></a>&nbsp;<a href="javascript:uploadifyRemove(&quot;' + json.fileId + '&quot;,&quot;image_&quot;)">删除</a><input name="'+Name+'" id="'+Name+'" type="hidden" value="'+json.file+'"/><br/></li>');
                art.dialog.data('fileListWarp',$("#fileListWarp").html());
            } else {
                alert(json.message);
            }
        }
    });
});



        function uploadifyRemove(fileId,attrName){
            if(confirm('本操作不可恢复，确定继续？')){
                $.post(
                    "<?php echo Yii::app()->createAbsoluteUrl("admin/uploadify/remove"); ?>",
                    {imageId:fileId},
                    function(res){
                        $("#"+attrName+fileId).remove();
                        art.dialog.data('fileListWarp',$("#"+Warp).html());
                    },
                    'json'
                );
            }
        }


	</script>
